package com.dao.impl;

import com.bean.Hw;
import com.bean.HwAttach;
import com.dao.BaseDao;
import com.dao.HwAttachDao;
import com.utils.SqlUtils;

import java.util.List;
import java.util.Map;

public class HwAttachDaoImpl extends BaseDao implements HwAttachDao {
    String[] strings = {"HwName"};
    @Override
    public List<HwAttach> selectForPageItems(int begin, int pageSize, String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";

        String sql = SqlUtils.pageSql(HwAttach.class, Hw.class, strings);
        return queryForList(HwAttach.class, sql, content, begin, pageSize);
    }

    @Override
    public Integer selectForPageTotalCount(String content) {
        if (content == null) {
            content = "";
        }
        content = "%" + content + "%";
        String sql = SqlUtils.countSql(HwAttach.class, Hw.class, strings);
        Number count = (Number) queryForSingleValue(sql, content);
        return count.intValue();
    }

    @Override
    public HwAttach selectBy(HwAttach hwAttach) {
        Map.Entry<String, Object[]> entry = SqlUtils.selectBy(hwAttach, Hw.class, strings);
        return queryForOne(HwAttach.class, entry.getKey(),entry.getValue());
    }

    @Override
    public int insert(HwAttach hwAttach) {
        Map.Entry<String, Object[]> entry = SqlUtils.insertSql(hwAttach, strings);
        return update(entry.getKey(), entry.getValue());
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        String sql = "delete from `hwAttach` where `id` = ?";
        return update(sql, id);
    }

    @Override
    public int updateByPrimaryKey(HwAttach hwAttach) {
        Map.Entry<String, Object[]> entry = SqlUtils.updateSql(hwAttach, strings);
        return update(entry.getKey(),entry.getValue());
    }

    @Override
    public int deleteByHwId(Integer hwId) {
        String sql = "delete from `hwAttach` where `hwId` = ?";
        return update(sql, hwId);
    }
}
